package com.op.mr3;

import android.app.Activity;
import android.os.Bundle;

import com.facebook.FacebookException;
import com.facebook.Session;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;

public class ShareDialog {

    private Activity  mActivity;

    private WebDialog mFeedDialog;

    public ShareDialog(Activity activity) {
        this.mActivity = activity;
    }

    public void show() {
        if (this.mFeedDialog != null) {
            return;
        }

        Bundle params = new Bundle();
        params.putString("name", "Mr.3");
        params.putString("caption", "Cool Math Game on Android:)");
        params.putString("description", "Play with Mr.3 and Give your Brain a workout.");
        params.putString("link", "http://play.google.com/store/apps/details?id=com.op.mr3");
        //params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

        WebDialog dialog = (new WebDialog.FeedDialogBuilder(mActivity, Session.getActiveSession(), params)).setOnCompleteListener(new OnCompleteListener() {

            @Override
            public void onComplete(Bundle values, FacebookException error) {
                mFeedDialog = null;
            }

        }).build();
        mFeedDialog = dialog;
        dialog.show();
    }

    public void dismiss() {
        WebDialog d = this.mFeedDialog;
        if (d != null) {
            d.dismiss();
            this.mFeedDialog = null;
        }
    }
}
